package com.plian.system.dao.sys.user;

import com.plian.Tools.pagedata.PageData;
import com.plian.system.dao.DaoSupport;
import com.plian.system.model.page.Page;
import com.plian.system.vo.sys.UserInfoVO;
import com.plian.system.vo.sys.UserReviewInfoVO;
import com.plian.system.vo.sys.UserRoleInfoVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class UserDao {
    @Resource(name = "daoSupport")
    private DaoSupport dao;

    public void save(PageData pd) throws Exception {
        dao.save("SysUserMapper.save", pd);
    }

    public void saveAll(List<PageData> list) throws Exception {
        dao.save("SysUserMapper.saveAll", list);
    }

    public void edit(PageData pd) throws Exception {
        dao.update("SysUserMapper.edit", pd);
    }

    public void editPhone(PageData pd) throws Exception {
        dao.update("SysUserMapper.editPhone", pd);
    }

    public void editOffid(PageData pd) {
        try {
            dao.update("SysUserMapper.editOffid", pd);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void deleteOffice(PageData pd) {
        try {
            dao.update("SysUserMapper.deleteOffice", pd);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public List<PageData> getUserByOffice(Long officeId) {
        try {
            List<PageData> forList = (List<PageData>) dao.findForList("SysUserMapper.getUserByOffice", officeId);
            return forList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public List<PageData> findByName(String username) throws Exception {
        return (List<PageData>) dao.findForList("SysUserMapper.findByName", username);
    }

    public PageData getUser(String username) throws Exception {
        return (PageData) dao.findForObject("SysUserMapper.getUser", username);
    }

    public PageData findbyid(String id) throws Exception {
        return (PageData) dao.findForObject("SysUserMapper.findbyid", id);
    }

    public void del_ids(List<String> ids) throws Exception {
        dao.delete("SysUserMapper.del_ids", ids);
    }

    public List<PageData> findListByType(PageData pd) throws Exception {
        return (List<PageData>) dao.findForList("SysUserMapper.findListByType", pd);
    }

    public List<PageData> list(Page page) throws Exception {
        return (List<PageData>) dao.findForList("SysUserMapper.listPage", page);
    }

    public List<PageData> listByCreatUser(Page page) throws Exception {
        return (List<PageData>) dao.findForList("SysUserMapper.listByCreatUserPage", page);
    }

    public List<PageData> listAll(PageData pageData) throws Exception {
        return (List<PageData>) dao.findForList("SysUserMapper.listAll", pageData);
    }

    public List<PageData> findByorg(String org) throws Exception {
        return (List<PageData>) dao.findForList("SysUserMapper.findByorg", org);
    }

    public List<PageData> getUsersUnderGZW() throws Exception {
        return (List<PageData>) dao.findForList("SysUserMapper.getUsersUnderGZW", null);
    }

    public List<String> findListById(List<String> ids) throws Exception {
        return (List<String>) dao.findForList("SysUserMapper.findListById", ids);
    }

    public PageData findOrgByUser(String id) throws Exception {
        return (PageData) dao.findOrgByUser("SysUserMapper.findOrgByUser", id);
    }

    public PageData findByEmployeeCode(String employeeCode) throws Exception {
        return (PageData) dao.findOrgByUser("SysUserMapper.findByEmployeeCode", employeeCode);
    }

    public void updateEmployeeCode(PageData pd) throws Exception {
        dao.update("SysUserMapper.updateEmployeeCode", pd);
    }

    public List<PageData> findByIds(List<String> ids) throws Exception {
        return (List<PageData>) dao.findForList("SysUserMapper.findByIds", ids);
    }

    public List<PageData> findByUsernames(List<PageData> list) throws Exception {
        return (List<PageData>) dao.findForList("SysUserMapper.findByUsernames", list);
    }

    public List<UserRoleInfoVO> findRoleByOrgIds(PageData pageData) throws Exception {
        return (List<UserRoleInfoVO>) dao.findForList("SysUserMapper.findRoleByOrgIds", pageData);
    }

    public List<UserReviewInfoVO> findReviewByOrgIds(PageData pageData) throws Exception {
        return (List<UserReviewInfoVO>) dao.findForList("SysUserMapper.findReviewByOrgIds", pageData);
    }

    public List<UserRoleInfoVO> findSalaryWaringUser() throws Exception {
        return (List<UserRoleInfoVO>) dao.findForList("SysUserMapper.findSalaryWaringUser", null);
    }

    public List<UserInfoVO> findUserByOrgIds(PageData pageData) throws Exception {
        return (List<UserInfoVO>) dao.findForList("SysUserMapper.findUserByOrgIds", pageData);
    }

    /**
     * 通过菜单名称（后台配置菜单的）和OrgId查询国资委用户信息
     *
     * @param pageData
     * @return
     * @throws Exception
     */
    public List<UserInfoVO> findUserByConfigFunAndOrgId(PageData pageData) throws Exception {
        return (List<UserInfoVO>) dao.findForList("SysUserMapper.findUserByConfigFunAndOrgId", pageData);
    }

    /**
     * 通过菜单名称（后台配置菜单的）和OrgId 查询配置的企业用户信息
     *
     * @param pageData
     * @return
     * @throws Exception
     */
    public List<PageData> findCompanyUserByConfigFunAndOrgId(PageData pageData) throws Exception {
        return (List<PageData>) dao.findForList("SysUserMapper.findCompanyUserByConfigFunAndOrgId", pageData);
    }

    /**
     * 通过菜单名称（后台配置菜单的）和 OrgIds 查询配置的企业用户信息
     *
     * @param pageData
     * @return
     * @throws Exception
     */
    public List<PageData> findCompanyUserByConfigFunAndOrgIds(PageData pageData) throws Exception {
        return (List<PageData>) dao.findForList("SysUserMapper.findCompanyUserByConfigFunAndOrgIds", pageData);
    }

    /**
     * 通过菜单名称（后台配置菜单的）和OrgId 查询配置的国资信息（带处室）
     *
     * @param pageData
     * @return
     * @throws Exception
     */
    public List<PageData> findOfficeUserByConfigFunAndOrgId(PageData pageData) throws Exception {
        return (List<PageData>) dao.findForList("SysUserMapper.findOfficeUserByConfigFunAndOrgId", pageData);
    }

    public void editStatus(PageData pd) throws Exception  {
        dao.update("SysUserMapper.editStatus", pd);
    }
}
